<template>
	<view class="shop-item" @click="goToShopItem(shop.id)">
		<view class="item-lev1">
			<view class="item-lev1-sub">
				<view class="shop-avatar">
					<image :src="shop.logoUrl || '/static/logo.png'" mode="scaleToFill" class="shop-image"></image>
				</view>
				<view class="shop-name">
					{{shop.shopName}}
				</view>
			</view>
			<view class="shop-share">
				<button type="primary" size="mini" plain @click.native.stop="shareShop(shop)">分享</button>
			</view>
		</view>
		<view class="item-lev2" v-if="shop.introduce">
			<view class="shop-intro">{{shop.introduce || ""}}</view>
		</view>
		<view class="item-lev3" v-if="shop.recommendedUrl">
			<view class="shop-tuijian-img">
				<view v-for="i in shop.recommendedUrl.split(',')" :key="i">
					<image :src="i || '/static/logo.png'" mode="scaleToFill" class="tuijian-image"></image>
				</view>
			</view>

		</view>
		<view class="item-lev4">
			<view class="buy-persons">购买人数{{shop.buyerCount > 100 ? shop.buyerCount : '< 100'}}</view>
			<view class="buy-fan" v-if="shop.fxzk">下单返{{shop.fxzk}}%</view>
			<!-- <view class="shop-distance">距您{{distanceText(shop.distance)}}</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		name: "shop-item",
		props: {
			shop: {
				type: Object,
				require: true,
			}
		},
		data() {
			return {

			};
		},
		methods: {
			distanceText(dis) {
				if (dis > 1000) {
					return (dis / 1000).toFixed(0) + ' km'
				}
				return dis + ' m'
			},
			goToShopItem(shopId) {
				uni.navigateTo({
					url: '/pages/shopInfo/shopInfo?shopId=' + shopId
				});
			},
			shareShop(shop) {
				this.$emit("onShareClick", shop)
			}
		}
	}
</script>

<style lang="scss">
	.shop-item {
		display: flex;
		flex-direction: column;
		width: 95%;
		margin: 0 auto;
		border-radius: 10px;
		padding: 10px 8px;
		box-shadow: 0 0 2px 1px #ccc;
		margin-bottom: 8px;
		background-color: #fff;

		.item-lev1 {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			border-bottom: 1px solid #cccccc;
			padding-bottom: 5px;
			margin-bottom: 5px;

			.item-lev1-sub {
				flex: 1;
			}

			.item-lev1-sub {
				display: flex;
				flex-direction: row;
				justify-content: flex-start;
				align-items: center;

				.shop-image {
					width: 35px;
					height: 35px;
					border-radius: 5px;

				}

				.shop-name {
					margin-left: 10px;
				}
			}

			.shop-share {
				button {
					padding: 0 10px;
					font-size: 13px;
				}
			}
		}

		.shop-intro {
			font-weight: bold;
			-webkit-line-clamp: 3;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			word-break: break-all;
			overflow: hidden;
			padding: 5px 0;
		}
		
		.item-lev2 {
			border-bottom: 1px solid #cccccc;
			padding-bottom: 5px;
			margin-bottom: 5px;
		}

		.item-lev3 {
			border-bottom: 1px solid #cccccc;
			margin-bottom: 5px;

			.shop-tuijian-img {
				display : flex;
				justify-content: space-between;
				align-items: center;
				.tuijian-image {
					width: 225rpx;
					height: 225rpx;
				}
			}
		}

		.item-lev4 {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.buy-fan {
				color: #d81e06;
				font-weight: bold;
			}
		}
	}
</style>